<?php

class Application_Model_Modulo extends Zend_Db_Table_Abstract {

    protected $_name = 'modulo';
    protected $_primary = 'codigo';
    private static $instance;

    public static function getInstance() {
        if (!isset(self::$instance)) {
            self::$instance = new Application_Model_Modulo();
            return self::$instance;
        }
        return self::$instance;
    }

    public function insert($data) {
        if (isset($data['descricao']) && isset($data['valor']) && isset($data['dt_cadastro'])
                && isset($data['dt_expiracao'])) {
            parent::insert($data);
        }
    }

    public function update(array $data, $where = '') {
        $where = 'codigo = ' . $data['codigo'];
        parent::update($data, $where);
    }

    public function getById($id) {
        return $this->fetchRow("codigo = " . $id ." and dt_exclusao is null");
    }

    public function getModulosLista(){
        $sql = ' select codigo, nome from modulo';
        return $this->getAdapter()->fetchAll($sql);
    }

    public function getModulos(){
        $sql = ' select chave, nome, labelPasta from modulo';
        return $this->getAdapter()->fetchAll($sql);
    }
    
    public function getChavesModulos(){
        $sql = ' select chave from modulo';
        $list = $this->getAdapter()->fetchAll($sql);
        
        $retorno;
        if(count($list) > 0){
            foreach ($list as $key => $value) {
                $retorno[]=$value['chave'];
            }
        }
        
        return $retorno;
    }

    public function getModulosListaCodigo(){
        $sql = ' select codigo from modulo';
        return $this->getAdapter()->fetchAll($sql);
    }
    
}